# -*- coding: utf-8 -*-
import scrapy
import bs4
from scrapy import Request

from zhilian.items import ZhilianItem


class ZhaopinSpider(scrapy.Spider):
    name = 'zhaopin'
    allowed_domains = ['www.zhaopin.com']
    #start_urls = ['http://www.zhaopin.com/']

    def start_requests(self):
        # urls = [
        #     'https://sou.zhaopin.com/?jl=801&kw=Python&kt=3&sf=0&st=0'
        # ]
        # for url in urls:
        url = 'https://sou.zhaopin.com/?jl=801&kw=Python&kt=3&sf=0&st=0'
        yield scrapy.Request(url=url,callback=self.parse)

    def parse(self, response):
        bs = bs4.BeautifulSoup(response.text,features="lxml")
        # jobs = bs.find_all("div",attrs={"class":"listContent"},recursive=True)
        for job in bs.find_all("div",attrs={"class":"listContent"},recursive=True):
            item = ZhilianItem()
            item["title"] = job.find("a").find("sapn",attrs={"class":"contentpile__content__wrapper__item__info__box__jobname__title"}).text
            item["salary"] = job.find("a").find("p",attrs={"class":"contentpile__content__wrapper__item__info__box__job__saray"}).text
            item["expi"] = job.find("a").find("li",attrs={"class":"contentpile__content__wrapper__item__info__box__job__demand__item"}).text
            yield item

        # yield scrapy.Request(url=)